home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / diskutil / ff32bin.zoo / disktest.c next >
C/C++ Source or Header  |  1991-03-16  |  5KB  |  147 lines

  1. /*
  2.     Disktest -- test the speed of reading and writing floppy
  3.     Copyright (C) 1989  by Robert Fischer
  4.  
  5.     This program costs no money; you can redistribute it and/or modify it
  6.     under the terms of the Lynxware General License as published by Robert
  7.     Fischer; either version 1, or (at your option) any later version. 
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     Lynxware General License for more details.
  13.  
  14.     You should have received a copy of the Lynxware General License
  15.     along with this program; if not, write to the author.
  16.  
  17.     To contact the author, call or write:
  18.         Robert Fischer
  19.         80 Killdeer Road
  20.         Hamden, CT    06517
  21.         (203) 288-9599
  22.         E-mail: fischer-robert@cs.yale.edu
  23. */
  24.  
  25.  
  26. /* This is meant to compile under Mark Williams C */
  27. /* For other C compilers, the GEMDOS and BIOS macros may need to be changed.. */
  28. /* ================= Pulled from my Include files ================== */
  29. typedef unsigned long LONG;
  30.  
  31. #define HZ_200          *( (LONG *)0x4BAL )
  32.  
  33. #define Cconin()        gemdos(0x1)
  34. #define Cconout(a)      gemdos(0x2,a)
  35. #define Cnecin()        gemdos(0x8)
  36. #define Cconws(a)       gemdos(0x9,a)
  37. #define Super(a)        gemdos(0x20,(LONG)(a))
  38. #define Getbpb(a)       bios(7,a)
  39. #define Rwabs(a,b,c,d,e)    bios(4,a,(LONG)b,c,d,e)
  40. #    define B_READ 0
  41. #    define B_WRITE 1
  42. #    define B_READ_NOCHANGE 2
  43. #    define B_WRITE_NOCHANGE 3
  44. #    define FLOP_A 0
  45. #    define FLOP_B 1
  46.  
  47. extern char *lmalloc();
  48.  
  49. /* ========================== Start of code ======================== */
  50. #define STARTSEC 27
  51. #define NUM_TRACKS 20    /* Number of tracks per trial */
  52. #define NUM_TRIALS 10    /* Number of trials to do */
  53. char *buf;
  54.  
  55. /* ------------------------------------------------------- */
  56. long clock()
  57. {
  58. LONG usp;
  59. long ret;
  60.     usp = Super(0);
  61.     ret = HZ_200;
  62.     Super(usp);
  63.     return ret;
  64. }
  65. /* ------------------------------------------------------- */
  66. insert_disk(sides)
  67. int sides;
  68. {
  69.     printf("Insert your junk %d-sided, 9-sector floppy in drive A\n",
  70.         sides);
  71.     Cnecin();
  72.     Getbpb(FLOP_A);
  73. }
  74. /* ------------------------------------------------------- */
  75. int test_disk(rowr, sides)
  76. int rowr;        /* 1 for write, 0 for read */
  77. int sides;
  78. {
  79. long start_time;
  80. int elapsed;
  81.     Rwabs(B_READ, buf, 2, STARTSEC - 9, FLOP_A);    /* Start motor going */
  82.     start_time = clock();
  83.     Rwabs(rowr, buf, NUM_TRACKS * 9 * sides, STARTSEC, FLOP_A);    /* Do the timed read */
  84.     elapsed = clock() - start_time;
  85.     return elapsed;
  86. }
  87. /* ------------------------------------------------------- */
  88. run_trial(rorw, sides)
  89. int rorw;        /* 1 for write, 0 for read */
  90. int sides;
  91. {
  92. long total;
  93. int tpt;    /* Time per track */
  94. int i;
  95.     /* Test the disk */
  96.     for (total = 0, i = 0; i < NUM_TRIALS; i++) {
  97.         total += test_disk(rorw, sides);
  98.     }
  99.     tpt = (total / (NUM_TRACKS * NUM_TRIALS));
  100.     printf("%cS %s: %d ms/track avg.\n",
  101.         (sides == 1 ? 'S' : 'D'),
  102.         (rorw == B_READ ? " Read" : "Write"),
  103.         tpt * 5);
  104. }
  105. /* ------------------------------------------------------- */
  106. main()
  107. {
  108. int c;
  109. int sides;
  110.     buf = lmalloc((long)NUM_TRACKS * 9L * 512L);
  111.  
  112.     Cconws("\033EDisktest -- test the speed of reading and writing floppy disks.\r\n");
  113.     Cconws("Copyright \275 1989  by Robert Fischer\r\n");
  114.     Cconws("Disktest comes with ABSOLUTELY NO WARRANTY.\r\n"
  115.     "This program is Lynxware and is subject to the terms of the Lynxware\r\n"
  116.     "General License; either version 1, or (at your option) any later version.\r\n\n"
  117.     );
  118.  
  119.     Cconws("To use Disktest, you need a formatted junk 9-sector single or\r\n");
  120.     Cconws("double-sided floppy disk, and a few minutes.  DISKTEST WILL DESTROY\r\n");
  121.     Cconws("THE DATA ON THE DISK YOU INSERT!  If you wish to continue, press 'C'.\r\n");
  122.     Cconws("Any other key will exit. ");
  123.  
  124.     c = Cconin() & 0xFF;
  125.     if (c != 'c' && c != 'C') exit(0);
  126.  
  127.     Cconws("\r\nHow many sides does your disk have? ");
  128.     c = Cconin() & 0xFF;
  129.     sides = (c == '2' ? 2 : 1);
  130.     Cconws("\r\n");
  131.  
  132.     insert_disk(sides);
  133.  
  134.     Cconws("Are you sure you want to continue with Disktest and destroy ALL THE\r\n");
  135.     Cconws("DATA in drive A? ");
  136.     c = Cconin() & 0xFF;
  137.     Cconws("\r\n\r\n");
  138.     if (c != 'y' && c != 'Y') exit(0);
  139.  
  140.     run_trial(B_READ, sides);
  141.     run_trial(B_WRITE, sides);
  142.  
  143.     Cconws("Press any key to return to the Desktop.\r\n");
  144.     Cnecin();
  145. }
  146. /* ------------------------------------------------------- */
  147.